'use strict';

angular.module('com.dcos.app').controller('ProjectDetailController',function($window,$scope,$uibModalInstance,ProjectCenterService,project,type,reload) {
  var vm = this;

  vm.userid=$window.sessionStorage.getItem("curUserId");
  vm.dept_id=$window.sessionStorage.getItem("curDept_Id");
  if(project)
    vm.project=project;
  else
      vm.project={
        "project_id":"",
        "project_name":"",
        "description":"",
        "status":"1",
        "dept_id":vm.dept_id,
        "create_userid":vm.userid
      };

  vm.ok = function () {
    if(type=="create"){
      ProjectCenterService.add(vm.project).then(function (response) {
          reload();
          $uibModalInstance.dismiss('cancel');
      });
    }else{
      ProjectCenterService.update(vm.project).then(function (response) {
          reload();
          $uibModalInstance.dismiss('cancel');
      });
    }
  }

  vm.cancel = function () {
    $uibModalInstance.dismiss('cancel');
  };
});
